package adfc2.tasks;

import adfc2.actions.PutAction;
import adfc2.core.Action;
import adfc2.core.Creature;
import adfc2.core.Item;
import adfc2.core.Task;
import adfc2.entities.Workshop;

public class PutTask extends Task {

    public final Item item;
    public final Workshop target;
    private MoveTask moving;

    public PutTask(Creature actor, Item item, Workshop target) {
        super(actor);
        this.item = item;
        this.target = target;
    }

    @Override
    public Action nextAction() {
        if (item.owner == target) {
            completed();
            return null;
        }
        if (actor.getXY() == target.getEntranceXY()) {
            return new PutAction(actor, item, target);
        } else {
            if (moving == null) {
                moving = new MoveTask(actor, target.getEntranceXY(), false);
            }
            return moving.nextAction();
        }
    }

    @Override
    public String shortName() {
        return "put " + item.shortName() + " to " + target.shortName();
    }
}
